package com.ljph.kit;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * Created by yuzhou on 16/11/30.
 */
public class PasswordKit {

  public void setAlgorithmName(String algorithmName) {
    this.algorithmName = algorithmName;
  }

  public void setHashIterations(int hashIterations) {
    this.hashIterations = hashIterations;
  }

  private String algorithmName = "md5";
  private int hashIterations = 2;

  public PasswordKit() {}
  public PasswordKit(String algorithmName) {
    this.algorithmName = algorithmName;
  }
  public PasswordKit(String algorithmName, int hashIterations) {
    this.algorithmName = algorithmName;
    this.hashIterations = hashIterations;
  }

  public String encrypt(String password, String salt) {
    return new SimpleHash(algorithmName, password, ByteSource.Util.bytes(salt), hashIterations).toHex();
  }

}
